/**
 * Created by Administrator on 2017/1/20.
 */
function moveElement(elementId, finalX, finalY, interval) {
    var supported = document.getElementById;
    if (!supported) {
        return false;
    }
    var elem = document.getElementById(elementId);
    if (!elem) {
        return false;
    }
    if (elem.movement) {
        clearTimeout(elem.movement);
    }
    if (!elem.style.left) {
        elem.style.left = '0px';
    }
    if (!elem.style.top) {
        elem.style.top = '0px';
    }
    var x = parseInt(elem.style.left);
    var y = parseInt(elem.style.top);
    var dist = 0;
    if (x == finalX && y == finalY) {
        return true;
    }
    if (x < finalX) {
        dist = Math.ceil((finalX - x) / 10);
        x += dist;
    }
    if (x > finalX) {
        dist = Math.ceil((finalX - x) / 10);
        x-=dist;
    }
    if (y < finalY) {
        dist = Math.ceil((finalX - y) / 10);
        y+=dist;
    }
    if (y > finalY) {
        dist = Math.ceil((finalX - y) / 10);
        y-=dist;
    }
    elem.style.left = x + 'px';
    elem.style.top = y + 'px';
    var repeat = 'moveElement(' + elementId + ',' + finalX + ',' + finalY + ',' + interval + ')';
    elem.meovment = setTimeout(repeat, interval);
}